import random
import smtplib
import string
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from app.config.config import config
from app.settings import env

def gen_email_code():
    list = random.sample(string.ascii_letters+string.digits,6)
    return "".join(list)

def send_email(email,code):
    print(code)
    emall_name = config[env].email_name #'liu-f-h@qq.com'
    passwd = config[env].passwd # 'qxlzkzwevoelcejj'
    msg_to = email #"py123321abcd@163.com"
    content = "慕慕手记注册验证码:<h1 style='color:red'>{}</h1>".format(code)
    msg = MIMEMultipart()
    msg["Subject"] = "慕慕手记验证码"
    msg["From"] = emall_name
    msg["To"] = msg_to
    # 发送邮件正文，html格式的
    msg.attach(MIMEText(content,"html","utf-8"))
    s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 邮箱服务器及端口号
    s.login(emall_name,passwd)
    s.sendmail(emall_name,msg_to,msg.as_string())






























